<template>
  <el-dialog
<<<<<<< HEAD
    title="编辑"
    :visible.sync="dialogVisible"
    width="30%"
    :before-close="handleClose"
  >
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="课程ID" prop="id">
        <el-input :disabled="true" v-model="ruleForm.id"></el-input>
      </el-form-item>
      <div class="block">
        <el-image
          :src="srcList[ruleForm.num]"
          style="width: 300px"
        ></el-image>
      </div>
      <el-form-item label="课程状态" prop="type">
        <el-select v-model="ruleForm.type" placeholder="请选择课程状态">
          <el-option label="上架" :value="0"></el-option>
          <el-option label="下架" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="课程名称" prop="title">
        <el-input v-model="ruleForm.title"></el-input>
      </el-form-item>
      <el-form-item label="报名费" prop="money">
        <el-input v-model="ruleForm.money"></el-input>
      </el-form-item>
      <el-form-item label="销量" prop="sales">
        <el-input v-model="ruleForm.sales"></el-input>
      </el-form-item>
      <el-form-item label="上传人" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="上传时间" prop="time">
        <el-date-picker
          v-model="ruleForm.time"
          type="date"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="closedailog">取 消</el-button>
      <el-button @click="submitForm(ruleForm)" type="primary">确 定</el-button>
=======
    title='修改'
    :visible.sync="dialogVisible"
    width="45%"
    :before-close="handleClose">

    <el-form 
       :model="ruleForm" 
       :rules="rules" 
       ref="ruleForm" 
       label-width="120px"> 
        <el-form-item label="工号" prop="userid">
            <el-input v-model="ruleForm.userid" disabled></el-input>
        </el-form-item>  
        <el-form-item label="姓名" prop="username" >
            <el-input v-model="ruleForm.username"></el-input>
        </el-form-item>  
        <el-form-item label="联系电话" prop="tel">
            <el-input v-model="ruleForm.tel"></el-input>
        </el-form-item>  
        <el-form-item label="学生数量" prop="num">
            <el-input v-model="ruleForm.num"></el-input>
        </el-form-item>  
         <el-form-item label="教师等级" prop="level">
            <el-input v-model="ruleForm.level"></el-input>
        </el-form-item> 
         <el-form-item label="上次教学时间" required>
          <el-col :span="11">
            <el-form-item prop="time">
              <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.time" style="width: 100%;"></el-date-picker>
            </el-form-item>
          </el-col>
          </el-form-item>
            <el-form-item label="是否禁用账户" prop="stop">
              <el-switch v-model="ruleForm.stop"></el-switch>
            </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary"  @click="submitForm('ruleForm')">提 交</el-button>
>>>>>>> 21fcf4125d81d09fe5f5af0867f669fea4339e75
    </span>
  </el-dialog>
</template>

<script>
<<<<<<< HEAD
import one from "../../../assets/image/kecheng-picture01.png";
import two from "../../../assets/image/kecheng-picture02.png";
import three from "../../../assets/image/kecheng-picture03.png";
import four from "../../../assets/image/kecheng-picture04.png";
import five from "../../../assets/image/kecheng-picture05.png";
import six from "../../../assets/image/kecheng-picture06.png";
import seven from "../../../assets/image/kecheng-picture07.png";
import eight from "../../../assets/image/kecheng-picture08.png";
import { updateFunApi } from "../../../api/courseApi";
export default {
  props: ["dialoglist"],
  data() {
    return {
      srcList: [one, two, three, four, five, six, seven, eight],
      dialogVisible: true,
      src: "",
      ruleForm: {
        id: "",
        title: "",
        type: "",
        num: "",
        money: "",
        sales: "",
        name: "",
        time: "",
      },
      rules: {
        type: [{ required: true, message: "请选择课程状态", trigger: "blur" }],
        money: [{ required: true, message: "请输入价格", trigger: "blur" }],
        sales: [{ required: true, message: "请输入数量", trigger: "blur" }],
        name: [{ required: true, message: "请输入上传人", trigger: "blur" }],
      },
    };
  },
  mounted() {
    this.ruleForm = { ...this.dialoglist };
  },
  methods: {
    submitForm() {
      console.log("this.ruleForm", this.ruleForm);
      updateFunApi(this.ruleForm).then((res) => {
        console.log(res);
        if (res.code == 200) {
          this.$emit("resettable");
        }
      });
    },
    closedailog() {
      this.$emit("closedialog");
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
          this.$emit("closedialog");
        })
        .catch((_) => {});
    },
  },
};
</script>

<style scoped>
.block {
  padding: 0px 130px;
}
</style>
=======
// 使用静态资源，先引入在赋值

import { updateFunApi } from '../../../api/homeApi'
export default {
    props:['row','dialogType'],
    data() {
       var validateuserid = (rule, value, callback) => {
        if (!/^([0]{2})([0-9]{5})$/.test(value)) {
          return callback(new Error('请输入7位数工号,以00开头'));
        }else{
           callback();
        }
       };
       var validateusername = (rule, value, callback) => {
        if (!/^(?:[\u4e00-\u9fa5·]{2,5})$/.test(value)) {
          return callback(new Error('请输入中文姓名,不超过五个字'));
        }else{
           callback();
        }
       };
       var validatetel = (rule, value, callback) => {
        if (!/^(?:(?:\+|00)86)?1[3-9]\d{9}$/.test(value)) {
          return callback(new Error('请输入11位联系电话'));
        }else{
           callback();
        }
       };
       var validatelevel = (rule, value, callback) => {
        if (!/^[1-9]{1}$/.test(value)) {
          return callback(new Error('请输入正确等级(1-9级)'));
        }else{
           callback();
        }
       };
      return {
        dialogVisible: true,
        ruleForm:{ //表单绑定的对象
            userid:'',//修改是需要保存id值的
            username:'',
            tel:'',
            num:'',
            level:'',
            time:'',
            stop:'',
        },
         rules: {//规则验证
         userid: [ //name是被验证的字段
            { required: true, message: '请输入工号', trigger: 'blur' },//判空
            { validator: validateuserid, trigger: 'blur' }
          ],
         username: [ //name是被验证的字段
            { required: true, message: '请输入用户姓名', trigger: 'blur' },//判空
            { validator: validateusername, trigger: 'blur' }
          ],
         tel: [ //name是被验证的字段
            { required: true, message: '请输入联系电话', trigger: 'blur' },//判空
            { validator: validatetel, trigger: 'blur' }
          ],
         num: [ //name是被验证的字段
            { required: true, message: '请输入学生数量', trigger: 'blur' },//判空
           
          ],
         level: [ //name是被验证的字段
            { required: true, message: '请输入等级', trigger: 'blur' },//判空
           { validator: validatelevel, trigger: 'blur' }
          ],
         time: [
            { required: true, message: '请选择日期', trigger: 'blur' }
          ],
         } 
      };
    },
    mounted(){
        this.ruleForm = {...this.row} //一层对象， 解构赋值是可以的  JSON.parse(JSON.stringify())
        
    },
    methods: {
       submitForm(formName) { //提交按钮
        this.$refs[formName].validate((valid) => {
          if (valid) { //验证通过
            console.log('success',this.ruleForm);
            updateFunApi(this.ruleForm).then(res=>{
             console.log(res)
             if(res.code==200){
                this.$emit("resettable")
             }
            })
          } else { //验证不通过
            console.log('error submit!!');
            return false;
          }
        });
      },  
      closeDialog(){  
        // 关闭弹框
        this.$emit('closedialog')
      },  
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
              // 关闭弹框
            this.$emit('closedialog')
          })
          .catch(_ => {});
      }
    }
  };
</script>

<style>

</style>
>>>>>>> 21fcf4125d81d09fe5f5af0867f669fea4339e75
